﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Vant.WpfControls.DrawingObject
{
    /// <summary>
    /// Interaction logic for InputDrawingObject.xaml
    /// </summary>
    public partial class InputDrawingObject : UserControl
    {
        public InputDrawingObject(CellTypeViewModelStyle cellStyle)
        {
            InitializeComponent();
            cellStyle.TextWrapping = TextWrapping.NoWrap;
            var viewModel = new InputDrawingObjectViewModel();
            if (cellStyle.Foreground == null)
            {
                cellStyle.Foreground = ColorHelper.Text;
            }
            viewModel.CellStyle = cellStyle;
            
            this.DataContext = viewModel;
        }

        public InputDrawingObjectViewModel ViewModel
        {
            get
            {
                return this.DataContext as InputDrawingObjectViewModel;
            }
        }
    }
    public class InputDrawingObjectViewModel : ModelBase
    {
        public virtual string placeholder { get; set; }

        public object leftIcon { get; set; }

        public object rightIcon { get; set; }

        public object arrowIcon { get; set; }
        public virtual bool isLink { get; set; }

        public bool border { get; set; }

        public bool required { get; set; }

        public bool IsDisabled { get; set; }

        public string text { get; set; }

        public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Left;

        public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Center;

        public Visibility LeftIconVisibility
        {
            get
            {
                return leftIcon != null ? Visibility.Visible : Visibility.Collapsed;
            }
        }

        public Visibility RightIconVisibility
        {
            get
            {
                return rightIcon != null ? Visibility.Visible : Visibility.Collapsed;
            }
        }
        public Visibility LinkIconVisibility
        {
            get
            {
                return isLink ? Visibility.Visible : Visibility.Collapsed;
            }
        } 
        
        public Visibility PlaceholderVisibility
        {
            get
            {
                return string.IsNullOrEmpty(this.text) ? Visibility.Visible : Visibility.Collapsed;
            }
        }

        private CellTypeViewModelStyle _cellStyle;
        public CellTypeViewModelStyle CellStyle
        {
            get
            {
                return this._cellStyle;
            }
            set
            {
                if (_cellStyle != value)
                {
                    this._cellStyle = value;
                    this.OnPropertyChanged();
                }
            }
        }
    }
}
